/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: RxBasePage
 * @Package com.rx.core.base
 * @Description: 分页查询结果
 * @author: 陈锦韬
 * @date: 2020\9\5 0005
 * @version V1.0
 * @Copyright: 2020 陈锦韬  All rights reserved.
 */
package com.rx.core.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author: Administrator
 * @Description: 分页查询结果
 * @date: 2020\9\5 0005
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class RxBasePage extends RxResponse {
    private static final long serialVersionUID = 1L;
    @Data
    @EqualsAndHashCode(callSuper=false)
    private static class PageData{
        long pageNum;
        long pageSize;
        long totalCount;
        long totalPage;
        Object pageData;
    }

    public static <T> RxBasePage create(List<T> list) {
        PageInfo<T> p=new PageInfo<>(list);
        RxBasePage rxDto = new RxBasePage();
        PageData pageData=new PageData();
        pageData.setPageNum(p.getPageNum());
        pageData.setPageSize(p.getPageSize());
        pageData.setPageData(p.getList());
        pageData.setTotalCount(p.getTotal());
        pageData.setTotalPage(p.getPages());
        rxDto.setResultData(pageData);
        return rxDto;
    }
    public <T> RxBasePage setListAgain(List<T> list) {
        PageData pageData = (PageData) this.getResultData();
        pageData.setPageData(list);
        return this;
    }
    public static <T> RxBasePage create(IPage<T> page) {
        RxBasePage rxDto = new RxBasePage();
        PageData pageData=new PageData();
        pageData.setPageNum(page.getCurrent());
        pageData.setPageSize(page.getSize());
        pageData.setPageData(page.getRecords());
        pageData.setTotalCount(page.getTotal());
        pageData.setTotalPage(page.getPages());
        rxDto.setResultData(pageData);
        return rxDto;
    }
}
